package com.aizhixin.lab.task.service;

import com.aizhixin.lab.company.entity.Classes;
import com.aizhixin.lab.company.service.ClassesService;
import com.aizhixin.lab.course.classes.entity.CourseClass;
import com.aizhixin.lab.task.domain.*;
import com.aizhixin.lab.task.entity.*;
import com.aizhixin.lab.task.repository.TaskStuAnswerRepository;
import lombok.extern.slf4j.Slf4j;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.common.core.LabReportCore;
import com.aizhixin.lab.common.core.UserInforCore;
import com.aizhixin.lab.common.dto.SortDTO;
import com.aizhixin.lab.common.utils.PageJdbcUtil;
import com.aizhixin.lab.company.domain.AccountDomain;
import com.aizhixin.lab.course.classes.domain.LabReportDomain;
import com.aizhixin.lab.course.classes.dto.CourseClassDTO;
import com.aizhixin.lab.course.classes.dto.CourseInfoDTO;
import com.aizhixin.lab.course.classes.entity.CourseClassStu;
import com.aizhixin.lab.course.classes.entity.LabReport;
import com.aizhixin.lab.course.classes.service.CourseClassService;
import com.aizhixin.lab.course.classes.service.CourseClassStuService;
import com.aizhixin.lab.course.course.entity.Course;
import com.aizhixin.lab.course.course.service.CourseService;
import com.aizhixin.lab.task.core.ExerciseType;
import com.aizhixin.lab.task.core.TaskInforCode;
import com.aizhixin.lab.task.repository.ReleaseTaskRepository;
import com.aizhixin.lab.task.repository.TaskRepository;
import com.alibaba.fastjson.JSONObject;

@Slf4j
@Service
@Transactional
public class ReleaseTaskService {
	@Autowired
	private ReleaseTaskRepository releaseTaskRepository;
	@Autowired
	private TaskService taskService;
	@Autowired
	private TaskQuestionsService taskQuestionsService;
	@Autowired
	private TaskQuestionChoiceService taskQuestionChoiceService;
	@Autowired
	private ReleaseTaskQuestionsService releaseTaskQuestionsService;
	@Autowired
	private ReleaseTaskQuestionChoiceService releaseTaskQuestionChoiceService;
	@Autowired
	private PageJdbcUtil pageJdbcUtil;
	@Autowired
	private TaskFileService taskFileService;
	@Autowired
	private ReleaseTaskFileService releaseTaskFileService;
	@Autowired
	private CourseClassService courseClassService;
	@Autowired
	private CourseClassStuService courseClassStuService;
	@Autowired
	private TaskStuInforService taskStuInforService;
	@Autowired
	private CourseService courseService;
	@Autowired
	private TaskStuAnswerRepository taskStuAnswerRepository;
	@Autowired
	private ClassesService classesService;

	public Map<String, Object> save(TaskDomain dto, Long userId) {
		Map<String, Object> result = new HashMap<>();
		if (StringUtils.isEmpty(dto.getId())) {
			ReleaseTask task = new ReleaseTask();
			BeanUtils.copyProperties(dto, task);
			task.setCreatedBy(userId);
			task.setId(UUID.randomUUID().toString());
			task = releaseTaskRepository.save(task);
			result.put(ApiReturnConstants.DATA, task);
			result.put(ApiReturnConstants.SUCCESS, true);
		} else {
			ReleaseTask task = releaseTaskRepository.findOne(dto.getId());
			if (task != null) {
				task.setTaskName(dto.getTaskName());
				task = releaseTaskRepository.save(task);
				result.put(ApiReturnConstants.DATA, task);
				result.put(ApiReturnConstants.SUCCESS, true);
			} else {
				result.put(ApiReturnConstants.SUCCESS, false);
				result.put(ApiReturnConstants.ERROR, "任务信息不存在！");
			}
		}
		return result;
	}

	public void save(ReleaseTask task) {
		releaseTaskRepository.save(task);
	}

	public ReleaseTask findById(String id) {
		return releaseTaskRepository.findByIdAndDeleteFlag(id, DataValidity.VALID.getState());
	}

	RowMapper<ReleaseTaskDomain> taskRm = new RowMapper<ReleaseTaskDomain>() {

		@Override
		public ReleaseTaskDomain mapRow(ResultSet rs, int rowNum) throws SQLException {

			ReleaseTaskDomain domain = new ReleaseTaskDomain();
			domain.setTaskId(rs.getString("task_id"));
			domain.setId(rs.getString("release_task_id"));
			domain.setCourseName(rs.getString("course_name"));
			domain.setTaskName(rs.getString("TASK_NAME"));
			domain.setCommitNumber(rs.getInt("COMMIT_NUM"));
			domain.setPendingNumber(rs.getInt("PENDING_NUM"));
			domain.setQuestionsNum(rs.getInt("QUESTIONS_NUM"));
			domain.setCourseChapterName(rs.getString("c_course_chapter_name"));
			domain.setClassName(rs.getString("class_name"));
			domain.setTotalNumber(courseClassService.getStuNum(rs.getString("course_id"),rs.getLong("CLASS_ID")));
			return domain;
		}
	};
	//查询任务列表
	public <T> Map<String, Object> findReleaseTaskPage(QueryTaskDomain domain, Long userId) {

		String querySql = "select rt.id as release_task_id,rt.COURSE_ID course_id,rt.is_count_down,rt.count_down,rt.CLASS_ID CLASS_ID,rt.TASK_ID task_id,c.`name` as course_name,rt.task_name,rt.COMMIT_NUM,rt.PENDING_NUM,rt.QUESTIONS_NUM ,cc.`name` AS c_course_chapter_name ,c2.`name` AS COURSE_MINUTIA_NAME , tc.`NAME` as class_name from `t_release_task` rt LEFT JOIN `c_course` c ON rt.COURSE_ID= c.id LEFT JOIN c_course_chapter as cc ON rt.COURSE_CHAPTER_ID=cc.id  LEFT JOIN c_course_chapter c2 on rt.COURSE_MINUTIA_ID =c2.id LEFT JOIN t_classes tc ON rt.CLASS_ID=tc.ID where rt.CREATED_BY = "
				+ userId + " and rt.DELETE_FLAG = 0  ";
		String countSql = "select count(*) from `t_release_task` rt LEFT JOIN `c_course` c ON rt.COURSE_ID= c.id LEFT JOIN c_course_chapter as cc ON rt.COURSE_CHAPTER_ID=cc.id  LEFT JOIN c_course_chapter c2 on rt.COURSE_MINUTIA_ID =c2.id LEFT JOIN t_classes tc ON rt.CLASS_ID=tc.ID where rt.CREATED_BY ="
				+ userId + " and rt.DELETE_FLAG = 0 ";

		if (!StringUtils.isEmpty(domain.getCourseId())) {
			querySql += " and rt.COURSE_ID='" + domain.getCourseId() + "'";
			countSql += " and rt.COURSE_ID='" + domain.getCourseId() + "'";
		}
		if (domain.getClassId()!=null&&domain.getClassId()!=0L) {
			querySql += " and rt.CLASS_ID= " + domain.getClassId();
			countSql += " and rt.CLASS_ID= " + domain.getClassId();
		}
//			if (null != domain.getChapterId() && domain.getChapterId().intValue() > 0L) {
//				querySql += " and lr.CHAPER_ID=" + domain.getChapterId() + "";
//				countSql += " and lr.CHAPER_ID=" + domain.getChapterId() + "";
//			}  

//			if (!StringUtils.isEmpty(domain.getName())) {
//				querySql += " and u.NAME like '%" + domain.getName() + "%'";
//				countSql += " and u.NAME like '%" + domain.getName() + "%'";
//			}

		List<SortDTO> sort = new ArrayList<SortDTO>();
		SortDTO dto = new SortDTO();
		dto = new SortDTO();
		dto.setKey("rt.CREATED_DATE");
		dto.setAsc(false);
		sort.add(dto);
		Map<String, Object> pageInfor = pageJdbcUtil.getPageInfor(domain.getPageSize(), domain.getPageNumber(), taskRm, sort, querySql,
				countSql);
//		List<ReleaseTaskDomain> list = (List<ReleaseTaskDomain>) pageInfor.get(ApiReturnConstants.DATA);
//		List<ReleaseTaskDomain> newList=new ArrayList<>();
//		for (ReleaseTaskDomain r: list){
//			newList.add(r);
//		}
//		pageInfor.put(ApiReturnConstants.DATA,newList);
		return pageInfor;
	}



	/**
	 * 根据课程ID获取学生成绩
	 * @param courseId 课程ID
	 * @param createBy	创建者
	 * @return
	 */
	public List<TaskResultListDomain> findTaskResult(String courseId,Long createBy,Long classId){
		List<ReleaseTask> byCourseIdAndCreatedBy =null;
		if (classId!=0L&&classId!=null){
			releaseTaskRepository.findByCourseIdAndCreatedByAndClassId(courseId, createBy,classId);
		}else {
			byCourseIdAndCreatedBy = releaseTaskRepository.findByCourseIdAndCreatedBy(courseId, createBy);
		}
		List<TaskResultListDomain> listDomains=new ArrayList<>();
		for (ReleaseTask releaseTask: byCourseIdAndCreatedBy){
			TaskResultListDomain taskResultListDomain = new TaskResultListDomain();
			String taskId = releaseTask.getId();
			Long classId1 = releaseTask.getClassId();
			Classes aClass = classesService.findClass(classId);
			taskResultListDomain.setClassName(aClass.getName());
			taskResultListDomain.setTaskName(releaseTask.getTaskName());
			taskResultListDomain.setTaskResultDomainList(findTaskResultByTaskId(taskId));
			listDomains.add(taskResultListDomain);
		}
		return listDomains;
	}
//	public TaskResultListDomain findTaskResult(String releaseTaskId){
//		String sql="SELECT tcl.`NAME` college_name,tp.`NAME` professional_name,tc.`NAME` class_name,tu.`name` stu_name,tts.result result  FROM t_task_stu_infor tts LEFT JOIN t_user tu ON tts.stu_id=tu.id LEFT JOIN t_classes tc ON tu.CLASS_ID=tc.ID LEFT JOIN t_professional tp ON tp.ID=tu.PROFESSIONAL_ID LEFT JOIN t_college tcl ON tc.COLLEGE_ID=tcl.ID WHERE tts.delete_flag=0 ";
//		if (!StringUtils.isEmpty(releaseTaskId)){
//			sql+="tts.release_task_id='"+releaseTaskId+"'";
//		}
//		return null;
//	}
	RowMapper<TaskResultDomain> taskResult = new RowMapper<TaskResultDomain>() {

		@Override
		public TaskResultDomain mapRow(ResultSet rs, int rowNum) throws SQLException {

			TaskResultDomain domain = new TaskResultDomain();
			domain.setStuName(rs.getString("stu_name"));
			domain.setClassName(rs.getString("class_name"));
			domain.setProfessionalName(rs.getString("professional_name"));
			domain.setCollegeName(rs.getString("college_name"));
			domain.setResult(rs.getString("result"));
			domain.setGrade(rs.getString("grade"));
			return domain;
		}
	};


	/**
	 * 根据任务ID获取该任务下的学生成绩
	 * @param taskId
	 * @return
	 */
	public List<TaskResultDomain> findTaskResultByTaskId(String taskId){
		String sql="SELECT tt.stu_name,tc.`NAME` as class_name,tp.`NAME` as professional_name,co.`NAME` as college_name,tt.result as result,tt.grade as grade FROM (((t_task_stu_infor tt LEFT JOIN t_user tu ON tt.stu_id=tu.id)LEFT JOIN t_classes tc ON tu.CLASS_ID = tc.ID)LEFT JOIN t_professional tp ON tc.PROFESSIONAL_ID = tp.ID)LEFT JOIN t_college co ON tc.COLLEGE_ID = co.id WHERE tt.release_task_id= '"+taskId +"'";
		List<TaskResultDomain> info = pageJdbcUtil.getInfo(sql, taskResult);
		return info;
	}


	public List<ReleaseTask> saveReleaseTask(ReleaseTaskDomain dto, AccountDTO accountDTO) {
		List<ReleaseTask> releaseTaskList=new ArrayList<>();
		for(String s:dto.getClassIdArr()) {
			ReleaseTask releaseTask = new ReleaseTask();
			String releaseTaskId = UUID.randomUUID().toString();
			releaseTask.setId(releaseTaskId);
			releaseTask.setTaskId(dto.getTaskId());
			Task task = taskService.findById(dto.getTaskId());
			releaseTask.setTaskName(task.getTaskName());
			releaseTask.setQuestionsNum(task.getQuestionsNum());
			releaseTask.setDownTime(new Date());
			releaseTask.setCreatedDate(new Date());
			releaseTask.setScoringMethod(dto.getScoringMethod());
			releaseTask.setTemplateId(dto.getTemplateId());
			releaseTask.setCreatedBy(accountDTO.getId());
			releaseTask.setCourseId(dto.getCourseId());
			releaseTask.setIsCountDown(dto.getIsCountDown());
			releaseTask.setCountDown(dto.getCountDown());
			CourseClass courseClass = courseClassService.findCourseClass(s);
			releaseTask.setClassId(courseClass.getClassId());
			releaseTask.setCourseChapterId(dto.getCourseChapterId());
			releaseTask.setCourseMinutiaId(dto.getCourseMinutiaId());
			releaseTask.setPendingNum(0);
			releaseTask.setCommitNum(0);
			releaseTask.setIsCountDown(task.getIsCountDown());
			releaseTask.setCountDown(task.getCountDown());
			List<CourseClassDTO> stuTotalNum = courseClassService.sumCourseClassStuNum(s);
			if (!stuTotalNum.isEmpty()) {
				CourseClassDTO courseClassDto = stuTotalNum.get(0);
				if (null != courseClassDto.getStuNum()) {
					releaseTask.setPendingNum(courseClassDto.getStuNum());
				}
			}
			this.copyQuestionsInfor(releaseTaskId, dto.getTaskId());
			releaseTask = releaseTaskRepository.save(releaseTask);
			releaseTaskList.add(releaseTask);
//			saveInfo(releaseTask,s);
			ReleaseTaskThread thread = new ReleaseTaskThread(releaseTask, s);
			thread.start();
		}
		return releaseTaskList;
	}
//	private void saveInfo(ReleaseTask releaseTask, String courseClassIds){
//		ArrayList<TaskStuInfor> taskStuList = new ArrayList<TaskStuInfor>();
//		List<AccountDomain> stuList = courseClassStuService.findAllByCourseClassIdIn(courseClassIds);
//		for (AccountDomain courseClassStu : stuList) {
//			TaskStuInfor taskStuInfor = new TaskStuInfor();
//			taskStuInfor.setId(UUID.randomUUID().toString());
//			taskStuInfor.setCourseMinutiaId(releaseTask.getCourseMinutiaId());
//			taskStuInfor.setCourseChapterId(releaseTask.getCourseChapterId());
//			taskStuInfor.setCourseClassId(courseClassStu.getCourseClassId());
//			taskStuInfor.setReleaseTaskId(releaseTask.getId());
//			taskStuInfor.setStuId(courseClassStu.getId());
//			taskStuInfor.setStuName(courseClassStu.getName());
//			taskStuInfor.setTaskStatus(TaskInforCode.TASK_STATUS_UNCOMMIT);
//			taskStuInfor.setIsShowGrade("show");
//			taskStuInfor.setIsShowAnswer("show");
//			taskStuInfor.setCreatedDate(new Date());
//			taskStuList.add(taskStuInfor);
//
//		}
//		taskStuInforService.saveList(taskStuList);
//
//	}
	class ReleaseTaskThread extends Thread {
		private ReleaseTask releaseTask;
		private String courseClassIds;

		public ReleaseTaskThread(ReleaseTask releaseTask, String courseClassIds) {
			this.releaseTask = releaseTask;
			this.courseClassIds = courseClassIds;
		}

		@Override
		public void run() {
			ArrayList<TaskStuInfor> taskStuList = new ArrayList<TaskStuInfor>();
			List<AccountDomain> stuList = courseClassStuService.findAllByCourseClassIdIn(courseClassIds);
			for (AccountDomain courseClassStu : stuList) {
				TaskStuInfor taskStuInfor = new TaskStuInfor();
				taskStuInfor.setId(UUID.randomUUID().toString());
				taskStuInfor.setCourseMinutiaId(releaseTask.getCourseMinutiaId());
				taskStuInfor.setCourseChapterId(releaseTask.getCourseChapterId());
				taskStuInfor.setCourseClassId(courseClassStu.getCourseClassId());
				taskStuInfor.setReleaseTaskId(releaseTask.getId());
				taskStuInfor.setStuId(courseClassStu.getId());
				taskStuInfor.setStuName(courseClassStu.getName());
				taskStuInfor.setTaskStatus(TaskInforCode.TASK_STATUS_UNCOMMIT);
				taskStuInfor.setIsShowGrade("show");
				taskStuInfor.setIsShowAnswer("show");
				taskStuInfor.setCreatedDate(new Date());
				taskStuList.add(taskStuInfor);

			}
			taskStuInforService.saveList(taskStuList);
		}
	}

	@Async
	public void copyQuestionsInfor(String releaseTaskId, String taskId) {

		List<TaskQuestion> questionsList = this.taskQuestionsService.getListTaskQuestion(taskId);
		if (null != questionsList && questionsList.size() > 0) {
			List<ReleaseTaskQuestion> questionCopyList = new ArrayList<ReleaseTaskQuestion>();
			List<ReleaseQuestionChoice> choiceCopyList = new ArrayList<ReleaseQuestionChoice>();
			HashMap<String, String> questionIdsMap = new HashMap<String, String>();
			HashMap<String, String> choiceIdsMap = new HashMap<String, String>();
			List<String> taskQuestionIds = new ArrayList<>();
			for (TaskQuestion taskQuestion : questionsList) {
				taskQuestionIds.add(taskQuestion.getId());
			}
			List<TaskQuestionChoice> taskQuestionsChoiceList = new ArrayList<>();
			if (!taskQuestionIds.isEmpty()) {
				taskQuestionsChoiceList = taskQuestionChoiceService
						.findByDeleteFlagAndTaskQuestionIdIn(DataValidity.VALID.getState(), taskQuestionIds);
			}

			for (TaskQuestion question : questionsList) {
				if (null != question) {
					ReleaseTaskQuestion questionCopy = new ReleaseTaskQuestion();
					BeanUtils.copyProperties(question, questionCopy);
					String questionCopyId = UUID.randomUUID().toString();
					questionCopy.setId(questionCopyId);
					questionCopy.setReleaseTaskId(releaseTaskId);
					questionCopyList.add(questionCopy);
					questionIdsMap.put(question.getId(), questionCopyId);
					if ((ExerciseType.MULTIPLE.getIntValue() .equals(question.getQuestionType())
							|| ExerciseType.SINGLE.getIntValue() .equals(question.getQuestionType())||ExerciseType.JUDGMENT.getIntValue().equals(question.getQuestionType()) )
							&& !taskQuestionsChoiceList.isEmpty()) {
						for (TaskQuestionChoice taskQuestionChoice : taskQuestionsChoiceList) {
							if (taskQuestionChoice.getTaskQuestionId().equals(question.getId())) {
								ReleaseQuestionChoice choiceCopy = new ReleaseQuestionChoice();
								BeanUtils.copyProperties(taskQuestionChoice, choiceCopy);
								String choiceCopyId = UUID.randomUUID().toString();
								choiceIdsMap.put(taskQuestionChoice.getId(), choiceCopyId);
								choiceCopy.setId(choiceCopyId);
								choiceCopy.setReleaseQuestionId(questionCopyId);
								choiceCopyList.add(choiceCopy);
							}

						}
					}
				}
			}
			releaseTaskQuestionsService.save(questionCopyList);
			if (choiceCopyList.size() > 0) {
				releaseTaskQuestionChoiceService.saveList(choiceCopyList);
			}

			copyAccessoryInfor(releaseTaskId, taskId, questionIdsMap, choiceIdsMap);
		}
	}

	@Async
	public void copyAccessoryInfor(String releaseTaskId, String taskId, HashMap<String, String> questionIdsMap,
			HashMap<String, String> choiceIdsMap) {

		List<TaskFile> questionAccessoryList = taskFileService.findAllByTaskId(taskId);
		if (null != questionAccessoryList && questionAccessoryList.size() > 0) {
			List<ReleaseTaskFile> questionAccessoryCopyList = new ArrayList<ReleaseTaskFile>();
			for (TaskFile accessory : questionAccessoryList) {
				if (null != accessory) {
					ReleaseTaskFile accessoryCopy = new ReleaseTaskFile();
					BeanUtils.copyProperties(accessory, accessoryCopy);
					String accessoryCopyId = UUID.randomUUID().toString();
					accessoryCopy.setId(accessoryCopyId);
					String questionsId = questionIdsMap.get(accessory.getTaskQuestionId());
					if (StringUtils.isEmpty(questionsId)) {
						continue;
					} else {
						accessoryCopy.setReleaseQuestionId(questionsId);
					}
					if (!StringUtils.isEmpty(accessory.getTaskChoiceId())) {
						String choiceCopyId = choiceIdsMap.get(accessory.getTaskChoiceId());
						if (!StringUtils.isEmpty(choiceCopyId)) {
							accessoryCopy.setReleaseChoiceId(choiceCopyId);
						}
					}
					accessoryCopy.setReleaseTaskId(releaseTaskId);
					questionAccessoryCopyList.add(accessoryCopy);
				}
			}
			releaseTaskFileService.saveList(questionAccessoryCopyList);
		}
	}

	public Map<String, Object> findCourseClassList(Long templateCourseId, Long userId) {
		Map<String, Object> result = new HashMap<>();
		List<Course> courseList = courseService.findCourseByCreatedByAndIsPublishAndIsArchive(userId, true, false);
		String courseIds = "";
		for (Course course : courseList) {
			if (null != course) {
				if (StringUtils.isEmpty(courseIds)) {
					courseIds = "'" + course.getId() + "'";
				} else {
					courseIds += ",'" + course.getId() + "'";
				}
			}
		}
		List<CourseClassDTO> classList = courseClassService.findCourseClassList(courseIds);
		result.put(ApiReturnConstants.DATA, classList);
		result.put(ApiReturnConstants.SUCCESS, true);
		return result;
	}

	public List<EasyWrongTopic> findEasyWrongTopic(String releaseTaskId){
		List<EasyWrongTopic> list=new ArrayList<>();
		List<ReleaseTaskQuestion> releaseTaskQuestions = releaseTaskQuestionsService.findByReleaseTaskIdOrderByOrderNumAsc(releaseTaskId);
		for (ReleaseTaskQuestion releaseTaskQuestion:releaseTaskQuestions){
			if (releaseTaskQuestion.getQuestionType() != 10&&releaseTaskQuestion.getQuestionType() != 20&&releaseTaskQuestion.getQuestionType() != 30) {
				continue;
			}
			Integer totalNum = taskStuAnswerRepository.countByReleaseQuestionIdAndReleaseTaskIdAndDeleteFlag(releaseTaskQuestion.getId(),releaseTaskId,DataValidity.VALID.getState());
			Integer errorNum = taskStuAnswerRepository.countByReleaseQuestionIdAndIsCorrectAndReleaseTaskIdAndDeleteFlag(releaseTaskQuestion.getId(), DataValidity.VALID.getState(),releaseTaskId,DataValidity.VALID.getState());
			if (totalNum==0){
				continue;
			}
			 int errorRate= errorNum*100/totalNum;
			if (errorRate>50){
				EasyWrongTopic easyWrongTopic = new EasyWrongTopic();
				easyWrongTopic.setOrderNum(releaseTaskQuestion.getOrderNum());
				easyWrongTopic.setReleaseQuestionId(releaseTaskQuestion.getId());
				easyWrongTopic.setErrorRate(errorRate);
				easyWrongTopic.setErrorNum(errorNum);
				list.add(easyWrongTopic);
			}
		}
		return list;
	}
	public QuestionAndStuAnswerDomain findQuestionAndStuAnswer(String releaseTaskQuestionId,Long stuId){
		QuestionAndStuAnswerDomain questionAndStuAnswerDomain = new QuestionAndStuAnswerDomain();
		ReleaseTaskQuestion releaseTaskQuestion = releaseTaskQuestionsService.findReleaseTaskQuestion(releaseTaskQuestionId);
		questionAndStuAnswerDomain.setQuestionContent(releaseTaskQuestion.getQuestionContent());
		questionAndStuAnswerDomain.setAnswer(releaseTaskQuestion.getAnswer());
		questionAndStuAnswerDomain.setQuestionType(releaseTaskQuestion.getQuestionType());
		if (questionAndStuAnswerDomain.getQuestionType()==10||questionAndStuAnswerDomain.getQuestionType()==20||questionAndStuAnswerDomain.getQuestionType()==30){
			List<ReleaseQuestionChoice> choiceList = releaseTaskQuestionChoiceService.getChoiceList(releaseTaskQuestionId);
			questionAndStuAnswerDomain.setQuestionChoiceList(choiceList);
		}
		TaskStuAnswer t = taskStuAnswerRepository.findByReleaseQuestionIdAndStuId(releaseTaskQuestionId, stuId);
		if (t!=null) {
			questionAndStuAnswerDomain.setStuAnswer(t.getStuAnswer());
		}
		questionAndStuAnswerDomain.setAnswer(releaseTaskQuestion.getAnswer());
		return questionAndStuAnswerDomain ;
	}
}
